package com.zxw.user.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zxw.common.core.base.res.BaseRes;
import com.zxw.user.domain.entity.RoleButton;
import com.zxw.user.domain.vo.RoleButtonUpdateVO;
import com.zxw.user.service.RoleButtonService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Xuewei.Zhang
 * @since 2022-02-27
 */
@RestController
@RequestMapping("/role-button")
@RequiredArgsConstructor
public class RoleButtonController {

    private final RoleButtonService roleButtonService;

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("获取角色、菜单对应的按钮ids")
    @GetMapping("/role-menu-btn_ids/{role_id}/{menu_id}")
    public BaseRes<List<Long>> getMenuIdsByRoleId(@PathVariable(value = "role_id") Long roleId,
                                                  @PathVariable(value = "menu_id") Long menuId) {
        List<Long> btnIds = roleButtonService.getBtnIdsByRoleIdAndMenuId(roleId, menuId);
        return BaseRes.ok(btnIds);
    }

    @ApiOperationSupport(author = "Xuewei.Zhang")
    @ApiOperation("批量更新角色权限")
    @PutMapping("/update/{roleId}/{menuId}")
    public BaseRes<RoleButton> update(@PathVariable Long roleId, @PathVariable Long menuId, @RequestBody RoleButtonUpdateVO roleButtonUpdateVO) {
        roleButtonUpdateVO.setRoleId(roleId);
        roleButtonUpdateVO.setMenuId(menuId);
        roleButtonService.batchUpdate(roleButtonUpdateVO);
        return BaseRes.okAdd();
    }

}
